<template>
	<el-dialog :title="titleMap[mode]" v-model="visible" customClass="customWidth" destroy-on-close @closed="$emit('closed')">
		<el-form :model="form" :rules="rules" ref="dialogForm" label-width="100px" label-position="left">
			<el-row :gutter="24">
				<el-col :lg="12">
					<el-form-item label="楼宇名称" prop="name">
						<el-input v-model="form.name" clearable maxlength="80"></el-input>
					</el-form-item>
				</el-col>
				<!-- <el-col :lg="12">
					<el-form-item label="所属片区" prop="district_id">
						<el-input v-model="form.district_id" clearable maxlength="80"></el-input>
					</el-form-item>
				</el-col> -->
				<el-col :lg="12">
					<el-form-item label="所属园区" prop="park_id">
						<!-- <el-input v-model="form.park_id" clearable maxlength="80"></el-input> -->
						<el-select v-model="form.park_id" placeholder="所属园区" @change="onSelectCity" clearable filterable style="width: 100%">
							<el-option
							v-for="item in parkList"
							:key="item.id"
							:label="item.name"
							:value="item.id">
							</el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :lg="12">
					<el-form-item label="楼宇总层数（聚合）" prop="total_number_pricing">
						<el-input v-model="form.total_number_pricing" clearable maxlength="80"></el-input>
					</el-form-item>
				</el-col>
				<el-col :lg="12">
					<el-form-item label="房间数量" prop="room_number">
						<el-input v-model="form.room_number" clearable maxlength="80"></el-input>
					</el-form-item>
				</el-col>
				<el-col :lg="12">
					<el-form-item label="功能类别" prop="function_type">
						<el-input v-model="form.function_type" clearable maxlength="80"></el-input>
					</el-form-item>
				</el-col>
				<el-col :lg="12">
					<el-form-item label="空间介绍" prop="space_intro">
						<el-input v-model="form.space_intro" clearable maxlength="80"></el-input>
					</el-form-item>
				</el-col>
				<el-col :lg="12">
					<el-form-item label="产业定位" prop="industry_positioning">
						<el-input v-model="form.industry_positioning" clearable maxlength="80"></el-input>
					</el-form-item>
				</el-col>
				<el-col :lg="12">
					<el-form-item label="招商政策" prop="investment_policy">
						<el-input v-model="form.investment_policy" clearable maxlength="80"></el-input>
					</el-form-item>
				</el-col>
				<el-col :lg="12">
					<el-form-item label="是否推荐" prop="recommended">
						<el-input v-model="form.recommended" clearable maxlength="80"></el-input>
					</el-form-item>
				</el-col>
				<el-col :lg="12">
					<el-form-item label="空间图片上传" prop="spatial_pictures">
						<el-input v-model="form.spatial_pictures" clearable maxlength="80"></el-input>
					</el-form-item>
				</el-col>
				<el-col :lg="12">
					<el-form-item label="附件上传" prop="attach_upload">
						<el-input v-model="form.attach_upload" clearable maxlength="80"></el-input>
					</el-form-item>
				</el-col>
			</el-row>
		</el-form>
		<template #footer>
			<el-button @click="visible=false">取 消</el-button>
			<el-button v-if="mode!='show'" type="primary" :loading="isSaveing" @click="submit()">保 存</el-button>
		</template>
	</el-dialog>

</template>
<script>
import selectUserDialog from "@/views/module/selectUserDialog";
import msgBoxCheckBox from "@/views/module/msgBoxCheckBox";
import AttachMenu from '@/views/module/attachMenu'
import {defineAsyncComponent} from "vue";
const scEditor = defineAsyncComponent(() => import('@/components/scEditor'));
export default {
	emits: ['success', 'closed'],
	components: {
		msgBoxCheckBox,
		selectUserDialog,
		AttachMenu,
		scEditor
	},
	data() {
		return {
			visible: false,
			isSaveing: false,
			isShowMsg:false,
			mode: "add",
			templates: [],
			fileList:[],
			userList:[],
			parkList:[],
			apiObj:this.$API.file.attach.uploadFile,
			titleMap: {
				add: '楼宇信息',
				edit: '楼宇档案',
			},
			form: {
				id:'',
				name:'',
				district_id:'',
				park_id: '',
				total_number_pricing:"",
				room_number:""
			},
			rules: {
				name: [
					{required: true, message: '园区名称不能为空', trigger: 'blur'}
				]
			}
		}
	},
	mounted() {
		this.getBuildingList();
		this.getParkList();
	},
	methods: {
		//显示
		open(mode = 'add') {
			this.mode = mode;
			this.visible = true;
			return this
		},
		publishDateAfter(time){
			return time.getTime()<(Date.now()-24*60*60*1000)
		},
		async getBuildingList(){
			let res = await this.$API.attractinvestment.building.getBuildingList.get();
			if (res.code == 200) {
				this.userList = res.data;
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		async getParkList(){
			let res = await this.$API.attractinvestment.park.getParkList.get();
			if (res.code == 200) {
				this.parkList = res.data.list;
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		submit() {
			this.$refs.dialogForm.validate(async (valid) => {
				if (valid) {
					this.isSaveing = true;
					var res;
					// delete this.form.rental_pricing
					// delete this.form.strata_fees
					delete this.form.total_number_pricing
					if (this.mode == "add") {
						res = await this.$API.attractinvestment.building.insertBuilding.post(this.form);
					} else if (this.mode == "edit") {
						res = await this.$API.attractinvestment.building.updateBuilding.post(this.form);
					}
					this.isSaveing = false;
					if (res.code == 200) {
						this.$emit('success')
						this.visible = false;
						this.$message.success("操作成功")
					} else {
						this.$alert(res.message, "提示", {type: 'error'})
					}
				}
			})
		},
		async setData(data) {
			let res = await this.$API.attractinvestment.building.getBuildingById.get({id:data.id});
			this.form.id = res.data[0].id
			this.form.name = res.data[0].name
			this.form.park_id = res.data[0].park_id
			this.form.total_number_pricing = res.data[0].total_number_pricing
			this.form.room_number = res.data[0].room_number
			this.form.function_type = res.data[0].function_type
			this.form.space_intro = res.data[0].space_intro
			this.form.industry_positioning = res.data[0].industry_positioning
			this.form.investment_policy = res.data[0].investment_policy
			this.form.recommended = res.data[0].recommended
			this.form.spatial_pictures = res.data[0].spatial_pictures
			this.form.attach_upload = res.data[0].attach_upload
			// this.form.id = data.id
			// this.form.name = data.name
			// this.form.district_id = data.district_id
			// this.form.park_id = data.park_id
			// this.form.total_number_pricing = data.total_number_pricing
			// this.form.room_number = data.room_number
		}
	}
}
</script>

<style>
.customWidth {
	width: 60%;
}
</style>
